﻿/*
创建人：longb
日期：2022-07-18
描述：材料收料确认js
*/
var page = {
    pagetotal: 0,
    pageSize: 20,
    pageNumber: 1,
    ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSNotProductMaterialApplyBillHandler.ashx",
    //初始化页面
    init: function () {
        page.bind();
        customizedEasyuiPagination('pp'); //定制化分页
    },
    //页面事件绑定
    bind: function () {
        //申领单信息
        $("#AuxMaterialApplyTable").datagrid({
            //checkOnSelect: false,
            //selectOnCheck: false,
            //singleSelect: true,
            rownumbers: true,
            onLoadSuccess: function (data) {
                $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
                customizedEasyuiPagination('pp'); //定制化分页
            },
            columns: [[
                 { field: 'ZSNPMATERIALAPPLYBILLID', width: 120, checkbox: true },
                 { field: 'ZSNPMATERIALAPPLYBILLNO', title: '申领单号', width: 130 },
                 { field: 'MATERIALCODE', title: '物料编码', width: 120 },
                 { field: 'MATERIALDESC', title: '物料描述', width: 120 },
		         { field: 'APPLYQTY', title: '申领数量', width: 80 }, //--
                 { field: 'UOMNAME', title: '单位', width: 90 }, 
                 { field: 'TOGETHERFLAG', title: '任务单号', width: 90 }, 
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 90 }, 
                 { field: 'PURPOSE', title: '用途', width: 90 },  
                 { field: 'APPLYNAME', title: '申领人', width: 90 },  
                 { field: 'APPLYDATE', title: '申领时间', width: 90 },  
                 { field: 'STATUS', title: '状态', width: 90 },  
                 { field: 'SENDOUTQTY', title: '实发数量', width: 80,  },
                 { field: 'SENDOUTUOM', title: '单位', width: 90 },
                 { field: 'OUTSTOREEMPLOYEENAME', title: '出库人', width: 80,},
                 { field: 'OUTSTOREDATE', title: '出库时间', width: 130 }
	           ]],
            onSelect: function (index, row) {
            },
            onCheckAll:function(rows){
            },
            onCheck:function(rowIndex,rowData){
            }
        });
        //分页事件
        $('#pp').pagination({
            onSelectPage: function (pageNumber, pageSize) {
                customizedEasyuiPagination('pp'); //定制化分页
                page.pageSize = pageSize; page.pageNumber = pageNumber;
                page.GetNPMaterialApplyBill();
            }
        });
        //绑定分页go按钮
        $('#pageGo').on("click", function () {
            var pageNumber = $(this).parents('tr').find('.pagination-num').val();
            page.pageNumber = pageNumber;
            page.GetNPMaterialApplyBill();
        });
        //清除按钮
        $('#btnReset').on("click", function () {
            page.reset(true, true);
            page.pageNumber = 1; page.pagetotal = 0
            $('#pp').pagination('refresh', {
                total: page.pagetotal,
                pageSize: page.pageSize,
                pageNumber: page.pageNumber
            });
        });
    },
    //查询
    searchData: function () {
        page.reset(false, true);
        page.pageNumber = 1;
        page.GetNPMaterialApplyBill();
    },
    //查询材料申领单信息
    GetNPMaterialApplyBill: function () {
        var frdata = $('#searchForm').serializeArray();
        var data = {};
        $.each(frdata, function () {
            data[this.name] = this.value
        });
        var param = {
            action: "GetNPMaterialApplyBill",
            pageSize: page.pageSize,
            pageNumber: page.pageNumber,
            data: JSON.stringify([data])
        };
        page.post(param, function (res) {
            if (res.Result) {
                //console.info(res);
                page.pagetotal = res.RowCount;
                $('#AuxMaterialApplyTable').datagrid('loadData', res.DBTable);
            }
        });
    },
    //申领单--收料确认
    ReciveConfirmNPMaterialApplyBill: function () {
        page.NPMaterialApplyBill("ReciveConfirmNPMaterialApplyBill");
    },
    NPMaterialApplyBill: function (action) {
        var ids = [];
        var rows = $('#AuxMaterialApplyTable').datagrid("getChecked");
        if (rows.length==0) { displayMessage("请勾选记录再进行操作", false); return; }
        $.each(rows, function (index, item) {
            if(item.SENDOUTQTY!=null){
                ids.push(item.ZSNPMATERIALAPPLYBILLID);
            }
        });
        if (ids.length == 0) { displayMessage("勾选记录实发数量为空,请确认数量再进行操作", false); return; }
        var param = {
            action: action,
            type:page.pageType,
            ids: ids.join(',')
        };
        page.post(param, function (res) {
            if (res.Result) {
                page.GetNPMaterialApplyBill();
            }
            displayMessage(res.Message, res.Result);
        });
    },
    //查询重置
    searchReset: function () {
        $('#searchForm').form('clear');
        page.bind();
    },

    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
    },
    //post数据
    post: function (param, callback) {
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});